﻿Imports System.Linq
Imports HTLibrary
Imports TNCDAL

Public Class LogController
    Private objRepository As New LogRepository

    Public Function GetLogList(ByVal id_action As Integer, ByVal userName As String, ByVal logContent As String, ByVal fromDate As Date, ByVal toDate As Date) As IQueryable
        Dim query = From p In objRepository.GetLogList(id_action, userName, logContent, fromDate, toDate)
                    Select New With {p.LogDate, p.tblAction.ActionName, p.LogContent, p.tblUser.UserName, p.HostName, p.Ip}
        Return query
    End Function

    Public Sub Insert(ByVal idAction As Integer, Optional ByVal logContent As String = "")
        Dim objLog As New tblLog
        objLog.ID_User = GeneralClassBAL._User.ID_User
        objLog.LogDate = Now
        objLog.ID_Action = idAction
        objLog.LogContent = logContent
        Dim objIPInfo As IPInfo = HTLibrary.CollectionHelper.GetIP()
        objLog.Ip = objIPInfo.Ip
        objLog.HostName = objIPInfo.HostName
        objRepository.Insert(objLog)
    End Sub

    Public Sub DeleteAll()
        objRepository.DeleteAll()
    End Sub
End Class
